import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.Image;
import com.lowagie.text.DocumentException;

import java.io.FileOutputStream;
import java.io.IOException;

public class Test {
    public static void main(String[] args){

        try {
            PdfReader reader = new PdfReader("c:\\1.pdf");
            PdfStamper stamper = new PdfStamper(reader,new FileOutputStream("c:\\2.pdf"));
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,    BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
            PdfContentByte over;
            int total = reader.getNumberOfPages() + 1;
            for (int i = 1; i < total; i++) {
            over = stamper.getOverContent(i);
            over.beginText();
            over.setFontAndSize(bf, 18);
            over.setTextMatrix(300, 30);
            over.showText("page " + i);
            over.endText();
            }
            stamper.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace(); 
        }

    }
}
